package com.shiyi.controller;

import com.shiyi.entity.Person;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import java.util.Arrays;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;

/**
 * @author qiu
 * @date 2021-03-04 下午 10:40
 * @since 1.0
 */
@Controller
@RequestMapping("/thymeleaf")
public class ThymeleafController {

    @RequestMapping("/first")
    public ModelAndView testThymeleaf(ModelAndView modelAndView) {
        modelAndView.addObject("thText", "th:text设置文本内容 <b>加粗</b>");
        modelAndView.addObject("thUText", "th:utext 设置文本内容 <b>加粗</b>");
        modelAndView.addObject("thValue", "thValue 设置当前元素的value值");
        modelAndView.addObject("thEach", Arrays.asList("th:each", "遍历列表"));
        modelAndView.addObject("thIf", "msg is not null");
        modelAndView.addObject("thObject", new Person("zhangsan", 12, "男", null, null));
        modelAndView.setViewName("thymeleaf");
        return modelAndView;
    }

    @RequestMapping("/standardExpression")
    public ModelAndView standardExpression(ModelAndView modelAndView) {
        modelAndView.addObject("Str", "Blog");
        modelAndView.addObject("Bool", true);
        modelAndView.addObject("Array", new Integer[]{1, 2, 3, 4});
        modelAndView.addObject("List", Arrays.asList(1, 3, 2, 4, 0));
        Map<String, String> hashMap = new HashMap<>(2);
        hashMap.put("thName", "${#...}");
        hashMap.put("desc", "变量表达式内置方法");
        modelAndView.addObject("hashMap", hashMap);
        modelAndView.addObject("Date", new Date());
        modelAndView.addObject("Num", 888.888D);
        modelAndView.setViewName("thymeleaf2");
        return modelAndView;
    }
}
